interface IImgSize extends Base.IObjectAny {
  width: number;
  height: number;
}
interface IWaterFallProps {
  replenish: number;
  maybe?: number;
}

class WaterFall {
  private maybe;
  private replenish;
  private topList: number[] = [];
  constructor(props: IWaterFallProps) {
    const { replenish, maybe } = props;
    this.maybe = maybe || 0;
    this.replenish = replenish;
  }
  public setStyle(item: IImgSize, index: number) {
    if (index === 0) this.topList = [];
    let itemHeight = 0;
    let styles: string[] = [];
    const position = this.setPosition(index);
    const imgHeight = +item.height <= 300 ? +item.height : 300;
    itemHeight = imgHeight + this.replenish;
    if (+item.status === 1) itemHeight = itemHeight + this.maybe;
    if (index < 2) {
      this.topList.push(itemHeight);
      const top = `top:${0}px`;
      styles = [top, position];
    } else {
      this.topList.push(this.topList[index - 2] + itemHeight);
      const top = `top:${this.topList[index - 2]}px`;
      styles = [top, position];
    }
    return styles.join(";");
  }
  private setPosition(i: number) {
    let position = "";
    switch (i % 2) {
      case 0: {
        position = "left:0px";
        break;
      }
      case 1: {
        position = "right:0px";
        break;
      }
    }
    return position;
  }
}

export { WaterFall };
